import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/ui/widgets/my_app_bar.dart';
import 'package:appflutterhomeschool/ui/widgets/user/collection_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/user/customization_screen_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/user/customization_tab_bar_view.dart';
import 'package:appflutterhomeschool/view_model/my/customization_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///用户： ninetailedfox
///时间： 2020/6/30
///邮箱： 1037438704@qq.com
///功能： 资源库
class CustomizationPage extends StatelessWidget {
  final int pageTag;

  CustomizationPage({this.pageTag});

  @override
  Widget build(BuildContext context) {
    return ProviderWidget<CustomizationViewModel>(
      model: CustomizationViewModel(context, pageTag: pageTag),
      onModelReady: (model) => model.initView(),
      builder: (context, viewModel, child) {
        return DefaultTabController(
          length: viewModel.listTab.length,
          child: Scaffold(
            backgroundColor: Colors.white,
            appBar: MyAppBar2(
              title: viewModel.textTabBar,
              rightIcon: CollectionWidget(visible: viewModel.pageTag == 0,onTap: (){
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => MyCollectionPage()));
                },),
            ),
            body: Column(
              children: [
                Container(
                  color: Colors.white,
                  child: Row(
                    children: <Widget>[
                      TabBar(
                        indicatorSize: TabBarIndicatorSize.label,
                        indicatorWeight: 2,
                        //选中的icon颜色
                        labelPadding: EdgeInsets.only(
                            left: ScreenUtil().setWidth(67 / 2),
                            right: ScreenUtil().setWidth(67 / 2)),
                        indicatorColor: Colors.blue,
                        isScrollable: true,
                        labelColor: Colors.black,
                        labelStyle: TextStyles.textDark37,
                        unselectedLabelStyle: TextStyles.textGray37,
                        unselectedLabelColor: Colors.grey,
                        tabs: viewModel.listTab,
                      ),
                      Expanded(child: Container()),
                      ScreenWidget(
                        visible: pageTag == 0,
                        onTap: viewModel.screenOnTap,
                      )
                    ],
                  ),
                ),
                Expanded(
                  child: Stack(
                    children: [
                      TabBarView(
                        children: [
                          CustomizationTabBarView(0),
                          CustomizationTabBarView(1),
                        ],
                      ),
                      //筛选页面
                      CustomizationScreenWidget(),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}

///我的收藏
class MyCollectionPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return CustomizationPage(
      pageTag: 1,
    );
  }
}
